package tutorial;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockTutorialBlock extends Block
{
	
	public BlockTutorialBlock(int id, Material material) 
	{
		super(id, material);
		this.setCreativeTab(CreativeTabs.tabBlock);
        this.setTickRandomly(true);
	}
	
	@SideOnly(Side.CLIENT)
    private Icon[] icons;
   
    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister)
    {
        icons = new Icon[4];
        String baseName = Tutorial.modid + ":" + (this.getUnlocalizedName().substring(5));
        icons[0] = par1IconRegister.registerIcon(baseName + "0");
        icons[1] = par1IconRegister.registerIcon(baseName + "1");
        icons[2] = par1IconRegister.registerIcon(baseName + "2");
        icons[3] = par1IconRegister.registerIcon(baseName + "3");
         
        //for(int i = 0; i < icons.length; i++)
        //{
        //    icons[i] = par1IconRegister.registerIcon(Tutorial.modid + ":" + (this.getUnlocalizedName().substring(5)) + i);
        //}
    }
    
    
    @SideOnly(Side.CLIENT)
    public Icon getIcon(int par1, int par2)
    {
        switch(par2)
        {
            case 0:
            	return icons[0];
            case 1:
            {
            	switch(par1)
                {
            		case 0:
            			return icons[1];
                    case 1:
                        return icons[2];
                    default:
                        return icons[3];
                }
            }
            default:
            {
            	System.out.println("Invalid metadata for " + this.getUnlocalizedName());
                return icons[0];
            }
        }
    }
   
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
    {
          for(int i = 0; i < 2; i++)
          {
                 par3List.add(new ItemStack(par1, 1, i));
          }
    }
    
    private int _count;
    
    public void updateTick(World world, int x, int y, int z, Random rand) 
    {
    	_count++;
    	
    	if (world != EventManager.World || ((_count % 100) == 0))
    	{
    		EventManager.RegisterWorld(world);
    	}
    	//setTickRandomly(false);
    }
    

    /**
     * How many world ticks before ticking
     */
    public int tickRate(World par1World)
    {
        return 1000000;
    }

}